from .exts import db


class GraderModel(db.Model):
    __tablename__ = 'grade'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(30), unique=True)

    # 建立关联
    students = db.relationship('StudentModel', backref='grade', lazy=True)


class StudentModel(db.Model):
    __tablename__ = 'student'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(30), unique=True)
    age = db.Column(db.Integer)
    # 外键
    grade_id = db.Column(db.Integer, db.ForeignKey('grade.id'))
